{extend name="../public/header" /}
{block name="body"}
<link rel="stylesheet" href="/public/admin/css/other.css" type="text/css">
<!-- 引入 js -->
<script src="/public/iceEditor/iceEditor.js"></script>
<body>
{include file="../public/common" /}
<fieldset class="layui-elem-field site-demo-button" style="padding:10px;">
	<div class="layui-row">
		<!--  -->
		<form id="form1" class="layui-form layui-form-pane" action="{:url('')}">
			<div class="layui-tab" lay-filter="test">
				<ul class="layui-tab-title">
					<li class="layui-this">基本信息</li>
					<li>上传</li>
				</ul>
				<div class="layui-tab-content">
					<div class="layui-tab-item layui-show">
						<section class="panel panel-padding">
							<div class="layui-form-item">
								<label class="layui-form-label">所属栏目</label>
								<div class="layui-input-inline">
									<select name="nav_id">
										<option value="0">请选择栏目</option>
										{volist name='listlm' id='vo' key='k'}
										{if empty($vo['voo'])}
										<option value="{$vo.id}" {if condition="$vo.id eq $info.nav_id"}selected{/if}>{$vo.name}</option>
										{else/}
										<optgroup label="{$vo.name}">
											{volist name="vo['voo']" id='sub' key='t' empty="暂时没有数据"}
											{if empty($sub['voval'])}
											<option value="{$sub.id}" {if condition="$sub.id eq $info.nav_id"}selected{/if}>&nbsp;├&nbsp;{$sub.name}</option>
											{else/}
											<optgroup label="{$sub.name}">
												{volist name="sub['voval']" id='voval' key='t' empty="暂时没有数据"}
												<option value="{$voval.id}" {if condition="$voval.id eq $info.nav_id"}selected{/if}>&nbsp;&nbsp;&nbsp;&nbsp;├&nbsp;{$voval.name}</option>
												{/volist}
											</optgroup>
											{/if}
											{/volist}
										</optgroup>
										{/if}
										{/volist}
									</select>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">文章标题</label>
								<div class="layui-input-block">
									<input type="text" name="title" value="{$info.title}" class="layui-input">
								</div>
							</div>
							<!--  -->
							<div class="layui-form-item">
								<label class="layui-form-label">状态</label>
								<div class="layui-input-inline">
									<input type="radio" name="status" {eq name="info.status" value="1"}checked{/eq} title="正常" value="1" checked />
									<input type="radio" name="status" {eq name="info.status" value="2"}checked{/eq} title="禁用" value="2" />
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">浏览数</label>
								<div class="layui-input-inline">
									<input type="text" name="view" value="{$info.view}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">关键字</label>
								<div class="layui-input-block">
									<input type="text" name="keywords" value="{$info.keywords}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">描述</label>
								<div class="layui-input-block">
									<input type="text" name="description" value="{$info.description|default=''}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">标签</label>
								<div class="layui-input-inline">
									<input type="text" name="label" value="{$info.label|default=''}" class="layui-input">
								</div>
								<div class="layui-form-mid layui-word-aux">多个请用‘|’分隔</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">采摘时间</label>
								<div class="layui-input-inline">
									<input type="text" id="pick_time" name="pick_time" value="{$info.pick_time|default=''}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">联系电话</label>
								<div class="layui-input-inline">
									<input type="text" name="tel" value="{$info.tel}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">联系地址</label>
								<div class="layui-input-block">
									<input type="text" name="address" value="{$info.address}" class="layui-input">
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">摘要</label>
								<div class="layui-input-block">
									<textarea name="subject" placeholder="请输入摘要" class="layui-textarea">{$info.subject|default=''}</textarea>
								</div>
							</div>
							<div class="layui-form-item">
								<label class="layui-form-label">文章内容：</label>
								<div class="layui-input-inline" style="width:80% !important;">
									<textarea name="content" id="content">{$info.content|default=''}</textarea>
								</div>
							</div>
						</section>
					</div>
					<div class="layui-tab-item">
						<section class="panel panel-padding">
							<!--  -->
							<div class="layui-upload" id="pic_img">
								<span class="fileinput-button">
									<span class="layui-btn">上传缩略图</span>
									<input type="file" id="pic" class="layui-btn file" accept="image/gif,image/jpeg,image/x-png"/>
								</span>
								<div class="layui-upload-list">
									<a href="{$info.thumb}" target="_blank"><img class="layui-upload-img" {if !empty($info.thumb)}src="{$info.thumb}"{/if} ></a>
									<input name="thumb" type="hidden" value="{$info.thumb|default=''}"/>
								</div>
							</div>
							<div class="layui-upload">
								<button type="button" class="layui-btn" id="up_video">上传短视频(20M以内)</button>
								<div class="layui-upload-list">
									<video class="layui-upload-video" id="up_video1" src="{$info.video|default=''}" controls="controls"></video>
								</div>
								<input name="video" id="video" type="hidden" value='{$info.video|default=''}'/>
							</div>
							<!--  -->
						</section>
					</div>
				</div>
			</div>
			<div class="layui-input-block">
				<input type="hidden" name="id" type="hidden" value="{$info.id|default=''}">
				<button class="layui-btn" lay-submit lay-filter="*">立即提交</button>
				<button type="reset" class="layui-btn layui-btn-primary">重置</button>
			</div>
		</form>
		<!--  -->
	</div>
</fieldset>
</body>
{/block}
{block name="script"}
<script>
	layui.use(['jquery','form','laydate','upload','element'], function(){
		var $ = layui.jquery
				,laydate = layui.laydate
				,upload = layui.upload
				,element = layui.element
				,form = layui.form;

		//年月范围
		laydate.render({
			elem: '#pick_time'
			,type: 'month'
			,range: true
		});

		//单图上传 缩略图
		$('#pic_img .file').change(function(event) {
			layer.msg('正在上传中',{icon:6,time:10000});
			var formData = new FormData();
			formData.append("file", $(this).get(0).files[0]);
			$.ajax({
				url:'{:url("upload/upFile")}',
				type:'POST',
				data:formData,
				cache: false,
				contentType: false,    //不可缺
				processData: false,    //不可缺
				success:function(res){
					if(res.code==undefined){
						console.log('res为json字符串',res);
						res = JSON.parse(res);
					}else{
						console.log('res为json对象',res);
					}
					//如果上传失败
					if(res.code != 1){
						return layer.msg('上传失败');
					}
					//上传成功
					layer.close(layer.index);
					layer.msg('上传成功',{icon:1,time:2000});
					var data = res.data;
					$('#pic_img .layui-upload-list a').attr('href', data.picurl);
					$('#pic_img .layui-upload-list img').attr('src', data.picurl);
					$('#pic_img .layui-upload-list input').val(data.picurl);
				},
				error: function(res){
					console.log(res);
				}
			});
		});

		//上传短视频
		upload.render({
			elem: '#up_video'
			,url: '{:url("upload/qiniuFile")}'
			,accept: 'video' //视频
			,size: 20480
			,before: function(obj){
				//预览
				obj.preview(function(index, file, result){
					$('#up_video1').attr('src', result);
				});
				//layer.msg('正在上传中',{icon:6,time:10000});
				var indexLoad = layer.load(2, {time: 10*1000});
			}
			,done: function(res){
				console.log(res);
				layer.close(layer.indexLoad);

				//如果上传失败
				if(res.code != 1){
					return layer.msg('上传失败');
				}
				//上传成功
				layer.msg('上传成功',{icon:1,time:2000});
				var data = res.data;

				$('#video').val(data.picurl);
			}
			,error: function(){
				//演示失败状态，并实现重传
				layer.close(layer.indexLoad);
				layer.msg('上传失败');
			}
		});

		form.render();
	});
</script>
<!-- ***************** -->
<script>
	ice.editor("content",function(){
		this.uploadUrl = '{:url("upload/upFileAll")}';
	});
</script>
<!-- ***************** -->
{/block}